package com.reremouse.rerebbs.web.mb.mag;

import com.reremouse.model.PartnerModel;
import com.reremouse.model.PartnerType;
import com.reremouse.rerebbs.dao.IPartnerDAO;
import com.reremouse.rerebbs.dao.IPartnerTypeDAO;
import com.reremouse.util.Cat;
import com.reremouse.util.SpringHelper;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean
@ViewScoped
public class AAPartner
        implements Serializable {
    PartnerModel partner = new PartnerModel();
    String tit = "";
    IPartnerDAO partnerDAO = (IPartnerDAO) SpringHelper.getSpringBean("PartnerDAO");
    IPartnerTypeDAO typeDAO = (IPartnerTypeDAO) SpringHelper.getSpringBean("PartnerTypeDAO");
    boolean flag = false;
    String nothing;
    List<SelectItem> ss = new ArrayList();

    public String getNothing() {
        return Cat.getUniqueId();
    }

    public void setNothing(String nothing) {
        this.nothing = nothing;
    }

    public String getTit() {
        return this.tit;
    }

    public void setTit(String tit) {
        this.tit = tit;
    }

    public PartnerModel getPartner() {
        return this.partner;
    }

    public void setPartner(PartnerModel partner) {
        this.partner = partner;
    }

    public List<SelectItem> getSs() {
        return this.ss;
    }

    public void setSs(List<SelectItem> ss) {
        this.ss = ss;
    }

    @PostConstruct
    public void init() {
        this.tit = "添加友情链接";
        HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String id = req.getParameter("id");
        if (id != null) {
            this.partner = this.partnerDAO.findPartnerModel(Long.parseLong(id));
            this.tit = "修改友情链接";
            this.flag = true;
        }
        if (this.partner.getUrl() == null) {
            this.partner.setUrl("http://");
        }
        loadSelects();
    }

    public void loadSelects() {
        List<PartnerType> pts = this.typeDAO.findAllPartnerType();
        this.ss.clear();
        for (PartnerType pt : pts) {
            SelectItem si = new SelectItem(pt.getId(), pt.getName());
            this.ss.add(si);
        }
    }

    public String save_action() {
        PartnerModel pp = this.partner;
        try {
            if (!this.flag) {
                this.partnerDAO.addPartnerModel(this.partner);
            } else {
                this.partnerDAO.updatePartnerModel(this.partner);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ListPartner?faces-redirect=true";
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.mag.AAPartner

 * JD-Core Version:    0.7.0.1

 */